<template>
    <div>
        <!-- https://upload.my2171.com/fileUpload -->
        <el-upload action="http://127.0.0.1:8081/photo/upload"
            list-type="picture-card"
            :data="options"
            :limit="1"
            :on-preview="onPreview"
            :on-success="onSuccess"
            :on-exceed="onExceed"
            :file-list="files">
            <i class="el-icon-plus" />
            <!-- <img v-if="imageUrl" :src="imageUrl" class="avatar">
  <i v-else class="el-icon-plus avatar-uploader-icon"></i> -->
        </el-upload>
        <el-dialog :visible.sync="dialogVisible">
            <img width="100%" :src="dialogImageUrl" alt="">
        </el-dialog>
    </div>
</template>

<script>
    import tool from "ut/tool";
    export default {
        name: 'WorldUpPicture',
        props: { value: String },
        data() {
            return {
                dialogImageUrl: '',
                dialogVisible: false,
                options: {
                    itemName: 'bishe',
                    type: 0
                },
                files: []
            };
        },
        watch: {
            value(url) {
                if (url) this.files.push({ url })
            }
        },
        methods: {
            onPreview(file) {
                this.dialogImageUrl = file.url;
                this.dialogVisible = true;
            },
            onSuccess(e) {
                this.$emit('input', e.data);
            },
            onExceed() {
                tool.notif('warning','警告','最多只能上传一张图片');
            }
        },
    };
</script>

<style lang="less" scoped></style>